package com.cqndt.disaster.device.controller;

import java.util.Map;
import java.util.List;
import java.util.HashMap;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageHelper;
import com.cqndt.disaster.device.util.Result;
import com.cqndt.disaster.device.domain.TabAttachment;
import com.cqndt.disaster.device.vo.TabVideoMonitoringVo;
import org.springframework.web.bind.annotation.PostMapping;
import com.cqndt.disaster.device.service.TabAttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cqndt.disaster.device.service.TabVideoMonitoringService;

/**
 * @author lgb
 * @date 2020-8-28
 * @说明 视频监控设备
 **/
@RestController
@RequestMapping("/tabVideo")
public class TabVideoDeviceController{
    @Autowired
    private TabVideoMonitoringService tabVideoMonitoringService;
    @Autowired
    private TabAttachmentService tabAttachmentService;

    /**
     * @param areaCode 区域编码
     * @param level 区域等级
     * @param projectId 所属项目
     * @param deviceName 设备名称
     * @param staticKey 设备厂商
     * @return 视频监控设备栽点
     **/
    @PostMapping(value="pointTabVideo")
    public Result pointTabVideo(TabVideoMonitoringVo vo){
//        TabUserVo userVo = getUser();
//        vo.setUserId(userVo.getId());
//        if(null == vo.getLevel()|| vo.getLevel()==""){
//            vo.setLevel(userVo.getLevel());
//            vo.setAreaCode(userVo.getAreaCode());
//        }
        List<TabVideoMonitoringVo> list = tabVideoMonitoringService.getListByCondition(vo);
        Result result = new Result();
        result.setData(list);
        return result;
    }

    /**
     * @param areaCode 区域编码
     * @param level 区域等级
     * @param projectId 所属项目
     * @param page 页数
     * @param limit 条数
     * @param deviceName 设备名称
     * @param staticKey 设备厂商（静态值staticNum=12）
     * @return
     **/
    @PostMapping(value="listTabVideoMonitoring")
    public Result listTabVideoMonitoring(TabVideoMonitoringVo vo){
//        TabUserVo userVo = getUser();
//        vo.setUserId(userVo.getId());
//        if(null == vo.getLevel()|| vo.getLevel()==""){
//            vo.setLevel(userVo.getLevel());
//            vo.setAreaCode(userVo.getAreaCode());
//        }
        PageHelper.startPage(vo.getPage(),vo.getLimit());
        PageInfo<TabVideoMonitoringVo> pageInfo = new PageInfo<TabVideoMonitoringVo>(
        		tabVideoMonitoringService.getListByCondition(vo));
        Result result = new Result();
        result.setCount((int)pageInfo.getTotal());
        result.setData(pageInfo.getList());
        return result;
    }
    /**
     * @param id 视频监控id
     * @return 设备基础信息、安装图片、视频图片
     **/
    @PostMapping(value="getTabVideoMonitoring")
    public Result getTabVideoMonitoring(Integer id){
        Result result = new Result();
        TabVideoMonitoringVo vo = tabVideoMonitoringService.getVideoById(id);
        List<TabAttachment> installImg = tabAttachmentService.selectAttachments(null == vo.getInstallPic()?null:vo.getInstallPic());
        List<TabAttachment> videoImg = tabAttachmentService.selectAttachments(null == vo.getResultPic()?null:vo.getResultPic());
        Map<String,Object> map = new HashMap<>();
        map.put("vo",vo);
        map.put("installImg",installImg);
        map.put("videoImg",videoImg);
        result.setData(map);
        return result;
    }
}